#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/5/21 11:14
# @Author  : mxc
# @File    : guanjianci1.py
# @Software: PyCharm
# -*- coding: utf-8 -*-
import random
import time
import urllib.request

import requests

import urllib.request
from bs4 import BeautifulSoup

# 爬取详细信息
def getInfo(url):
    c=[]
    # 通过浏览器开发者模式查看访问使用的user_agent及cookie设置访问头（headers）避免反爬虫,且每隔一段时间运行要根据开发者中的cookie更改代码中的cookie
    #user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
    user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
    '''
    cookie = 'f=n; commontopbar_new_city_info=102|成都|cd; commontopbar_ipcity=cd|成都|0; suid=7596740840; '\
                'id58=c5/nfGCjKCFLtjXNAwSxAg==; wmda_uuid=acdea8881ae1c0d5ead5725bc3fcc4b3; wmda_new_uuid=1; '\
                '58tj_uuid=822286d6-d701-4fbd-b5ee-bbc09967df7b; als=0; '\
                'xxzl_deviceid=yTqhPUdhf6T741GkaoDf9mOAvdSmrKKAw7oDDi/SRu4HCby+kMMfaPFE8nijAMM5;'\
                ' wmda_visited_projects=;11187958619315;10104579731767; xxzl_smartid=c6397d68d3db4935b85fd2550b21f796; '\
                '58home=cd; city=cd; sessid=227CB0C1-F0D8-4A96-9F72-203AE251AEEF; '\
                'aQQ_ajkguid=0A7372BF-1B9A-4FB5-8FAB-2F36CB5D72E7; '\
                'ctid=15; wmda_visited_projects=;11187958619315;10104579731767;8788302075828;'\
                ' __xsptplus8=8.1.1621384301.1621384301.1#4|||||##jqvT8uISWYzgcPUCpYufk6WU9TkfXbm7#; '\
                'fzq_h=fd8be794e7343e19379cb352916d15f7_1621384326426_34436ab60f7b429b91552392bb2da36b_3738299289; '\
                'new_uv=14; utm_source=; spm=; init_refer=https%3A%2F%2Fcallback.58.com%2F; '\
                'wmda_session_id_11187958619315=1621559469532-ab39c88d-6d6f-d9e1; f=n; new_session=0; crmvip=""; '\
                'dk_cookie=""; ppStore_fingerprint=060490C422345A3B8A3392BA29927F9DA647298E8A8B9844＿1621563210970;'\
                ' xzfzqtoken=DeDAI0qx5lnfR73qmo1xba9SACGADHoS349N+mNnwso93zBrTvEei3Kes2rqexjNin35brBb//eSODvMgkQULA==; '\
                'xxzl_cid=f4c80c337713434fab287a8e36ce3e7d; xzuid=306bb027-b0f2-4444-96ea-438c562d063d; '\
                'PPU="UID=79839879631391&UN=t0qdc07qd&TT=18c304663bce1a036acf847882983b20&PBODY=VXMY2Pkg6ACkSvgr0OtiZi'\
                '-ud3DOGdHqMV3etDrvOxEw8Vg8TQ6OuTel5e-RnB3dr_zj3L4hoLzYIvF0voa6iXU-Gcb-YEHIlSPNZv4l0je_JMsTdRvnEcD8_exCqs'\
                '_FPzONNiWty5hzdAkw_H0563gjruktRW-wsACV6-BzSUM&VER=1"; www58com="UserID=79839879631391&UserName=t0qdc07qd"; '\
                '58cooper="userid=79839879631391&username=t0qdc07qd"; 58uname=t0qdc07qd'
                '''
    cookie='f=n; commontopbar_new_city_info=102|成都|cd; suid=1234842657; id58=c5/nfGCjKCFLtjXNAwSxAg==; wmda_uuid=acdea8881ae1c0d5ead5725bc3fcc4b3; wmda_new_uuid=1; 58tj_uuid=822286d6-d701-4fbd-b5ee-bbc09967df7b; als=0; xxzl_deviceid=yTqhPUdhf6T741GkaoDf9mOAvdSmrKKAw7oDDi/SRu4HCby+kMMfaPFE8nijAMM5; wmda_visited_projects=;11187958619315;10104579731767; xxzl_smartid=c6397d68d3db4935b85fd2550b21f796; 58home=cd; city=cd; sessid=227CB0C1-F0D8-4A96-9F72-203AE251AEEF; aQQ_ajkguid=0A7372BF-1B9A-4FB5-8FAB-2F36CB5D72E7; ctid=15; wmda_visited_projects=;11187958619315;10104579731767;8788302075828; __xsptplus8=8.1.1621384301.1621384301.1#4|||||##jqvT8uISWYzgcPUCpYufk6WU9TkfXbm7#; commontopbar_new_city_info=102|成都|cd; commontopbar_ipcity=cd|成都|0; wmda_session_id_11187958619315=1622102257444-5034102b-81f5-d8eb; utm_source=; new_uv=20; init_refer=https%3A%2F%2Fcallback.58.com%2F; spm=; wmda_session_id_10104579731767=1622102279981-aac06b6a-9735-548d; crmvip=""; dk_cookie=""; www58com="UserID=79839879631391&UserName=t0qdc07qd"; 58cooper="userid=79839879631391&username=t0qdc07qd"; 58uname=t0qdc07qd; new_session=0; f=n; PPU=UID=79839879631391&UN=t0qdc07qd&TT=89a66606e94ab8c1d6083cb5e1b91d5a&PBODY=Hmk0VWaBKXDARZZH-gRoRalMh-j5KQh4Cw64_i5Ylj0iUaeKTUW5EhCOCRroBfICB6Defnt1bCoj51Fy7NId0buNhDJGwGxLvYAQHB_ceXBrRzfHYe97R-CFS9WWWUVzAfHpIuyC726JlwZo-LqyCBchn7fy8qGnMU6oUh4kmNA&VER=1; ppStore_fingerprint=060490C422345A3B8A3392BA29927F9DA647298E8A8B9844＿1622103648699; xzfzqtoken=rDLJadnZrRi6fmf3q5rrkcv7QYNyDKKWbBCp4cjNi4XbwIe8oT6pOqE6QVb3sMgDin35brBb//eSODvMgkQULA==; xxzl_cid=f4c80c337713434fab287a8e36ce3e7d; xzuid=306bb027-b0f2-4444-96ea-438c562d063d'
    headers = {"User-Agent": user_agent, "Cookie": cookie}
    response = urllib.request.urlopen(url)
    print(response)
    soup = BeautifulSoup(
        response,
        'html.parser',
        from_encoding='utf-8'
    )
    #print(soup)
    b = soup.find('ul', class_='introduce-item').find('li').find('span', class_='a2').find_all('em')
    for i in b:
        d = str(i)
        c.append(d[4:-5])
    return c


